package main

import (
	"flag"
	"fmt"
	"net/http"

	"gitee.com/thubcc/rtlmmap/web"
	"github.com/gin-gonic/gin"
)

var (
	argListen = flag.Int("listen", 8080, "web listen port")
	argSDir   = flag.String("s", "static/hweb", "web static")
	argTDir   = flag.String("t", "templates/hweb/", "web template")
	routers   = make(map[string]func(*gin.Context))
)

func InstallRouter(pre []func(), r *gin.Engine) {
	for _, p := range pre {
		p()
	}
	for k, v := range routers {
		r.GET(k, v)
	}
}

func main() {
	flag.Parse()
	r := gin.Default()
	web.LoadTemplate(*argTDir)
	InstallRouter([]func(){RouteInit, HandleInit}, r)
	r.StaticFS("/static", http.Dir(*argSDir))
	r.Run(fmt.Sprintf(":%d", *argListen))
}
